/**
 * 
 */
package com.gragra.sampling.nonproj;

import com.gragra.sampling.PopulationSamplingStructure;
import com.gragra.sampling.nonproj.structures.nonprojective.NonProjDepdTree;
import com.gragra.sampling.sequentialStructure.ExtensionLevels;
import com.gragra.sampling.sequentialStructure.WordType;
import it.unimi.dsi.fastutil.ints.IntSet;

/**
 * @author Christoph Teichmann
 * 19.10.2013
 */
public class DMVRoot extends DMV
{
	/**
	 * 
	 */
	private double	functionWordConstraint;
	/**
	 * @param population
	 * @param tags
	 * @param headHeadAlpha
	 * @param stopAlpha
	 * @param functionWordConstraint
	 * @param nounWordConstraint
	 */
	public DMVRoot(int population, IntSet tags, double headHeadAlpha,
			double stopAlpha, double functionWordConstraint,
			double nounWordConstraint,double structMax, double structRed)
	{
		super(population, tags, headHeadAlpha, stopAlpha, structMax, structRed);
		this.functionWordConstraint = -functionWordConstraint;
		this.nounWordConstraint = -nounWordConstraint;
	}
	/**
	 * 
	 */
	private double	nounWordConstraint;
	@Override
	protected double makeDistAndOtherConstraints(
			PopulationSamplingStructure pss, int thread)
	{
		double val = 0.0;
		NonProjDepdTree tree = (NonProjDepdTree) pss;
		for(int pos=0;pos<tree.getLength();++pos)
		{val += makeDistanceAndOtherConstraints(pos,tree,thread);}
		return super.makeDistAndOtherConstraints(pss, thread)+val;
	}
	/**
	 * 
	 * @param pos
	 * @param tree
	 * @param thread
	 */
	protected double makeDistanceAndOtherConstraints(int pos, NonProjDepdTree tree, int thread)
	{
		double val = 0.0;
		int head = tree.getHeadPosition(pos, thread);
		if(head == tree.getDependencyRootPosition())
		{
			WordType wt = (WordType) tree.getExtensionInformation().getFiniteInformation(pos, ExtensionLevels.WordTypeLevel);
			if(wt != null)
			{
				switch(wt)
				{
				case Noun:
					val = this.functionWordConstraint;
					break;
				case Function:
					val = this.nounWordConstraint;
					break;
				default:
					val = 0.0;
					break;
				}
			}
		}
		return val;
	}
}